<?php
//session_start();
header('Content-type:text/html;charset=utf-8');
header('Content-type: application/json');
header('Access-Control-Allow-Origin:*');
include_once './dbConfig.php';
include_once './public.php';


if ($_POST) {
    $name = $_POST['user'];
    $psw = md5($_POST['psw']);

    if (isset($_POST['postType']) && $_POST['postType'] == 'getCode') {
        $weCode = $_POST['randomCode'];
        $phpCode = getCode();
        $msg = ['msg' => $weCode, 'status' => $phpCode];
        if (strtolower($weCode) != strtolower($phpCode)) {
            $msg = ['msg' => '验证码失败!', 'status' => 0];
            reponseEvent($msg);
        }
    }

    $selectSql = 'select * from lgz_users where name="' . $name . '"';
    $result = $link->query($selectSql);
    if ($result->num_rows) {
        $arr = [];
        while ($item = $result->fetch_assoc()) {
            array_push($arr, $item);
        }
        if ($psw === $arr[0]['password']) {
            $msg = ['msg' => '登录成功！', 'status' => 1];
//            $_SESSION['loginUserName'] = $name;
        } else {
            $msg = ['msg' => '密码错误！', 'status' => 0];
        }
    } else {
        $msg = ['msg' => '"' . $name . '" 用户未注册', 'status' => 0];
    }
    reponseEvent($msg);
}

